﻿/**************************************************
* 版权所有:Copyright (C) 
* 作    者:蔡海翔
* 创建日期:2014/6/16 13:37:17
* 描    述:
* 修改日期:
* 修改内容:
****************************************************/

using IntelligentQuery.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace DataAccess
{
    public interface IEntityRepository<TEntity> where TEntity : class //这里使用泛型接口
    {
        /// <summary>
        /// 获得实体集合
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="orderBy"></param>
        /// <param name="includeProperties"></param>
        /// <returns></returns>
        IQueryable<TEntity> Get(Expression<Func<TEntity, bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, string includeProperties = "");
        IQueryable<TEntity> Get(QueryModel model, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, string includeProperties = "");
        /// <summary>
        /// 根据实键值获得单个实体
        /// </summary>
        /// <param name="Key"></param>
        /// <returns></returns>
        TEntity GetByKey(params object[] Key);
        /// <summary>
        /// 插入单个实体
        /// </summary>
        /// <param name="entity"></param>
        void Insert(TEntity entity);
        /// <summary>
        /// 插入实体集合
        /// </summary>
        /// <param name="list"></param>
        void Insert(IList<TEntity> list);
        /// <summary>
        /// 根据主键值删除单个实体
        /// </summary>
        /// <param name="Key"></param>
        void Delete(params object[] Key);
        /// <summary>        
        /// 删除单个实体       
        /// </summary>
        void Delete(TEntity entity);
        /// <summary>
        /// 删除实体集合
        /// </summary>
        /// <param name="list"></param>
        void Delete(IList<TEntity> list);
        /// <summary>
        /// 更新单个实体
        /// </summary>
        /// <param name="entity"></param>
        void Update(TEntity entity);
        /// <summary>
        /// 更新实体集合
        /// </summary>
        /// <param name="list"></param>
        void Update(IList<TEntity> list);

        IEnumerable<TEntity> GetWithRawSql(string query, params object[] parameters);
        IEnumerable<TEntity> GetwhithdbSql(string query, params object[] parameters);
        int ExecSqlCommand(string sql, params object[] parameters);
    }
}
